package com.cat.binaryTree02;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/6eUYwP/description/?envType=problem-list-v2&envId=xhsq2On3
 * @create 2025/10/2 21:18
 * @since JDK17
 */

public class Solution02 {
    int f(TreeNode root, long sum) {
        if (root == null) {
            return 0;
        }
        sum -= root.val;
        return f(root.left, sum) + f(root.right, sum) + (sum == 0 ? 1 : 0);
    }
    public int pathSum(TreeNode root, int sum) {
        if (root == null) {
            return 0;
        }
        return pathSum(root.left, sum) + pathSum(root.right, sum) + f(root, sum);
    }
}
